package com.rs2hd.content;

import com.rs2hd.event.Event;
import com.rs2hd.model.Player;
import com.rs2hd.model.World;

/**
 * Handles the regaining of player energy.
 *
 * @author Graham
 */
public class RunEnergyEvent extends Event {

    /**
     * Creates the server-wide run event to run every 2 seconds.
     */
    public RunEnergyEvent() {
        super(4000);
    }

    @Override
    public void execute() {
        for (Player p : World.getInstance().getPlayerList()) {
            if ((p.getWalkingQueue().isRunToggled() || p.getWalkingQueue().isRunning()) && p.getSprites().getSecondarySprite() != -1) {
                continue;
            } else {
                if (p.getRunEnergy() < 100) {
                    p.setRunEnergy(p.getRunEnergy() + 1);
                }
            }
        }
    }

}
